<template>
  <view>
    <view class="goods-list">
     <my-goods v-for="(goods, i) in goodsList" :key="i" :goods="goods"></my-goods>
     <view v-if="finished">
       已经到底了
     </view>
    </view>
  </view>
</template>

<script>
	export default {
		data() {
			return {
				params:{
          cid:'',
          query:'',
          pagenum:1,
          pagesize:10
        },
        goodsList:[],
        finished:false,
        loading:false
			};
		},
    onLoad(options) {
      console.log(options);
       if(options.query) this.params.query=options.query
       if(options.cid) this.params.cid=options.cid
       this.getGoodsList()
    },
    methods: {
      async getGoodsList() {
        this.loading = true
          let {data:res} = await uni.$http.get('/api/public/v1/goods/search',this.params)
          if(res.meta.status !==200) {
            this.loading = false
            return this.$showToast()
          }
          this.goodsList = [...this.goodsList,...res.message.goods]
          if(res.message.goods.length < this.params.pagesize){
            //结束
            this.finished = true
          }else{
            this.params.pagenum++
            this.loading = false
          }
      }
    },
    onReachBottom() {
      if(this.finished) return false
      if(this.loading) return false
      this.getGoodsList()
    },
    async onPullDownRefresh() {
      this.params.pagenum=1,
      this.loading=this.finished = false
      await this.getGoodsList()
      uni.stopPullDownRefresh()
    }
	}
</script>

<style lang="scss">

</style>
